Setting Internet Pass-Thru Mode

Latest update: September 2018

In this tutorial, you will learn how to control FlashAir by using the iSDIO driver API on a RaspberryPi and set the Internet Pass-Thru Mode.

Sample environment

HW:Raspberry Pi 3 Model B + microSD->SDconversion adapter
OS:Raspbian (NOOBS ver.2.4.3)
NW:Access point with Internet connection


Using the microSD conversion adapter, connect FlashAir to the microSD slot of Raspberry Pi 3 as shown above.

Sample code execution procedure

  1. Prepare to be able to launch RaspberryPi from FlashAir as preparation.
    Also, please write APPMODE=0 in the CONFIG file of the SD_WLAN folder.
    See "Booting Raspberry Pi with FlashAir".
  2. Download sample code environment from here and deploy it on RaspberryPi.
    The deployment location can be anywhere.
  3. When deployed, it will be expanded with the following configuration, so you will move from the terminal to the sample folder.
    iSDIO_tutorial_sample
    |-inc folder (iSDIO driver API header section)
    |  |- isdio_api.h
    |  |- isdio_wlan_api.h
    |  |- isdioreg.h
    |  └─ mmc.h
    |
    |-sample folder
    |  |- iSDIO_tutorial_sample.c (This tutorial sample code)
    |  └─ Makefile
    |
    └─src folder (iSDIO driver API source section)
      |- isdio_api.c
      |- isdio_wlan_api.c
      └─ isdioreg.c
  4. Run make in the terminal. If successful, a sample folder called isdio_sample will be created.
    However, since the access point names and passwords connected to the Internet differ depending on the environment, please refer to here and change.
  5. Execute isdio_sample created in 4.
    However, you need administrator privileges to use the iSDIO driver. Please execute as follows.
    > sudo ./isdio_sample

I will explain the downloaded sample code (iSDIO_tutorial_sample.c).

Initialize iSDIO card control information to use FlashAir.

iSDIO_tutorial_sample.c(Partial reference)

iSDIO_INFO_t *s_info;                                   /* iSDIO card control information pointer */
char *s_device = "/dev/mmcblk0" ;                       /* SD card device information */
/* iSDIO initialization */
s_info = iSDIO_Init(s_device);  
printf(" info=0x%p\n", s_info);
if (s_info != NULL) {
  printf("info->fno=%d\n", s_info->fno);
  system("mount /dev/mmcblk0p1 /mnt");
  • Line 33
    Prepare a pointer to obtain the start address of iSDIO card control information.
    The iSDIO card control information is acquired as the return value of iSDIO_Init and used as a handler in each command and response.
  • Line 34
    Please change SD card device information depending on the environment because device information of FlashAir is set.
  • Line 53
    To mount FlashAir, change it according to your environment.

Search for access points that FlashAir can recognize.

iSDIO_tutorial_sample.c(Partial reference)

/* Acquire information on surrounding access points */
result = iSDIO_WLAN_Scan(s_info, s_seq_id ++);

if (result == E_iSDIO_OK) {
  /* Wait for completion of the iSDIO command execution process */
  timeout = 20000;          /* Scan's timeout is 20 seconds, so 20000 ms */
  cmd_success = FALSE;
  /* Wait for WLAN_Scan response */
  cmd_success = response_wait(s_info, (s_seq_id-1), iSDIO_WLAN_SCAN, timeout);

  if (cmd_success == FALSE) {
    printf("WLAN_Scan response error !!!\n");
  }
  else {
  • Line 55
    Since iSDIO_WLAN_Scan is an asynchronous function, it is necessary to wait for a response in line 62.
    Response at line 55 is the success or failure of the execution of the iSDIO_WLAN_Scan command, and the response wait at line 62 is the success or failure of the execution result of the iSDIO_WLAN_Scan command.
    See here about command and response.
    In addition, the sequence ID of the argument is set to a unique value each time a new command is issued. Therefore, incrementing is performed after using sequence ID.
  • Line 62
    When response data is acquired, it decides which command execution response by command ID and sequence ID.
    Therefore, we wait for response with the value -1 from the current sequence ID to set the sequence ID when iSDIO_WLAN_Scan command is executed.

Set yourself as an access point while connecting to the Internet using FlashAir.

iSDIO_tutorial_sample.c(Partial reference)

uint8_t apssid[32]          = "myflashair";               /* FlashAir (AP side) Wireless LAN SSID */
uint8_t apnetworkKey[64]    = "password0123";             /* FlashAir (AP side) Wireless LAN network key */
uint8_t brgssid[32]         = "LANSSID";                  /* Internet (STA side) Wireless LAN SSID */
uint8_t brgnetworkKey[64]   = "lanpassword0123";          /* Internet (STA side) Wireless LAN network key */
uint32_t encMode            = iSDIO_WLAN_ENCMODE_WPA2_PSK_AND_AES;  /* Operating mode = 6 */
        /* When there is an access point around */
        /* Acquire the access point name to determine whether there is a target STA */
        for(lp=0;lp<num;lp++) {
          memset(getssid,0x00,32);            /* Access point name acquisition buffer clear */
          /* Acquire access point name with specified number */
          result = iSDIO_WLAN_GetSSID(s_info, lp , getssid);
          if(result != E_iSDIO_OK) {
            printf("WLAN_GetSSID get error !!!\n");
            exit(0);
          }
          printf("SSID#%d SSID=%s\n",lp, getssid);
          if(strstr((const char *)getssid, (const char *)brgssid)) {
            /* Bridge setting with target STA*/
            result = iSDIO_WLAN_Bridge(s_info, s_seq_id++,
                        apssid, sizeof(apssid),
                        apnetworkKey, sizeof(apnetworkKey),
                        encMode,
                        brgssid, sizeof(brgssid),
                        brgnetworkKey, sizeof(brgnetworkKey));
            if(result != E_iSDIO_OK) {
                printf("Bridge Set error!!!\n");
                exit(0);
            }
            break;
          }
        }
  • Line 93
    Set the SSID and its length for FlashAir itself to become an access point.
  • Line 94
    Set the access point's network key and its length.
  • Line 95
    Set the operation mode of the access point. In Internet Pass-Thru Mode, operation mode = 6 is fixed.
  • Line 96
    Set the SSID of the station side connected to the Internet and its length length.
  • Line 97
    Set the network key of the station side connected to the Internet and its length length.
important point

iSDIO_WLAN_Bridge does not work unless FlashAir is in disconnected state.
If FlashAir is already connected to another device, execute iSDIO_WLAN_Disconnect first.
If you want to know the connection status, when iSDIO_WLAN_Check_WLANConnect is executed, the connection status is output to the argument connect.

Response wait processing

We will explain response wait processing waiting for the result of asynchronous command.

iSDIO_tutorial_sample.c(Partial reference)

/* Sample function waiting for command response */
bool_t response_wait(iSDIO_INFO_t *s_info, uint32_t seq_id, uint32_t cmd_id, int32_t timeout)
{
  iSDIO_CommandResponseStatus_t *status;
  int32_t timeout_cnt = timeout / 10;    // ms / 10
  bool_t cmd_success = FALSE;

  /* Loop until the command response status exits from running or it times out */
  do {
    status = iSDIO_ReadCommandResponseStatus(s_info);
    if ((status->response_status != iSDIO_COMMAND_PROCESSING) && (status->cmd_id==cmd_id)) {
      if (status->response_status == iSDIO_PROCESS_SUCCEEDED) {
        cmd_success = TRUE;
      }
      break;
      printf("res_wait=%d\n",status->response_status);
    }
    sleep(10);    // Wait 10ms
    timeout_cnt --;
  } while (timeout_cnt > 0);
  return cmd_success;
}
  • Line 160
    Internal function that reads FlashAir register information Command Response Status.
    Get the response status of the command.
  • Line 161
    If the response status is not being processed and it is a response to the executed command, the response is normal and the response wait exits and the return value is returned as TRUE.
  • Lines 168-170
    Timeout processing when the response status is still being processed.
    In this sample, the response status is confirmed in units of 10 ms, and the response wait for the timeout time of the argument is done.
    In case of timeout, FALSE is returned as return value.

Execution result

Let's run it.

> sudo ./isdio_sample
dev/mmcblk0 open success
info=0x27268
info->fno=1
SSID#1 SSID=LANSSID
WLAN_Bridge set success
WLAN_BridgeGetInfoByRegister get response success
  • Lines 2-4
    Success log display and FlashAir's device handle ID are displayed only when FlashAir is recognized correctly.
  • Line 5
    The order in which the SSIDs were found and the access point name are displayed for the number of access points found in the Scan or whether the corresponding access point is found.
    The last displayed item is the corresponding access point.
    If it can not be found, an error log will be displayed.
  • Line 6
    The log of success is displayed only when the setting of Internet Pass-Thru Mode succeeds.
    If the connection fails, an error log is displayed.
  • Line 7
    Only when the acquisition of the bridge information succeeded is the log display of success.
    Please make sure that you can accesshttp://flashair/by connecting to the SSID "myflashair" from a PC / smartphone etc. not connected to the Internet.
    Also, make sure you can connect to the Internet.
    If information acquisition fails, an error log is displayed.

About command · response

The asynchronous commands are as follows.

  • iSDIO_WLAN_Scan
  • iSDIO_WLAN_Connect
  • iSDIO_WLAN_Establish
  • iSDIO_WLAN_WiFiDirect
  • iSDIO_WLAN_StartWPS
  • iSDIO_WLAN_StartWPSAP
  • iSDIO_WLAN_Disconnect
  • iSDIO_WLAN_SetCurrentTime
  • iSDIO_WLAN_Abort
  • iSDIO_WLAN_ReadResponse
  • iSDIO_WLAN_SetPowerSaveMode
  • iSDIO_WLAN_SetCannel
  • iSDIO_WLAN_SendHTTPMessageByRegister
  • iSDIO_WLAN_SendHTTPFileByRegister
  • iSDIO_WLAN_SendHTTPSSLMessageByRegister
  • iSDIO_WLAN_SendHTTPSSLFileByRegister
  • iSDIO_WLAN_SendHTTPMessageByFile
  • iSDIO_WLAN_SendHTTPFileByFile
  • iSDIO_WLAN_SendHTTPSSLMessageByFile
  • iSDIO_WLAN_SendHTTPSSLFileByFile
  • iSDIO_WLAN_Request
  • iSDIO_WLAN_SetCertificate
  • iSDIO_WLAN_SetCertificateByFile
  • iSDIO_WLAN_StartP2PSender
  • iSDIO_WLAN_StartP2PReceiver
  • iSDIO_WLAN_GetFile
  • iSDIO_WLAN_ReadIDList
  • iSDIO_WLAN_SelectMAC
  • iSDIO_WLAN_DeselectMAC
  • iSDIO_WLAN_SetID
  • iSDIO_WLAN_Bridge
  • iSDIO_WLAN_BridgeGetByRegister

Synchronous commands are as follows.

  • iSDIO_Init
  • iSDIO_WLAN_WriteSharedMemory
  • iSDIO_WLAN_ReadSharedMemory
  • iSDIO_WLAN_GetFlashAirVersion
  • iSDIO_WLAN_GetSSIDs
  • iSDIO_WLAN_GetSSID
  • iSDIO_WLAN_GetStatusData
  • iSDIO_WLAN_GetResponseData
  • iSDIO_WLAN_GetVersion
  • iSDIO_WLAN_SetWaitResponseTime
  • iSDIO_WLAN_Check_WLANConnect
  • iSDIO_WLAN_Check_WLAN
  • iSDIO_WLAN_Get_WLAN_Status

Sample code environment complete set

iSDIO_tutorial_sample.zip (24KB)